import { inject, ref } from 'vue'
import {
  EnumAllViewType, EnumOpTypes,
  loadImgMprType, loadImgType,
  loadSingleViewType
} from '@renderer/views/imgViewer/imgTypes'
import { aspectType } from '@renderer/views/imgOp/type'
import axios from 'axios'


export const useWatchStackAspect = () => {
  const {
    ioInstance,
    sendMsg,
    baseUri,
    throughGatewayFlag
  } = inject('pyImgHandlerIo') as any

  const getNew = (msg: loadImgType) => {
    sendMsg(msg)
  }

  const aspects = ref<{
    stack: aspectType
  }>({
    stack: {
      width: 0,
      height: 0
    }
  })
  const setAspect = (args: aspectType) => {
    const { width, height } = args
    aspects.value[EnumAllViewType.stack] = {
      width,
      height
    }

    const msg: loadSingleViewType = {
      viewType: EnumAllViewType.stack,
      opType: EnumOpTypes.getImg,
      size: {
        width,
        height
      }
    }
    getNew(msg)
  }
  return {
    aspects,
    setAspect
  }
}

export const useWatchMprAspectChange = (onMprSizeGotCb) => {

  const mprAspects = ref({
    ax: null,
    sag: null,
    cor: null
  })
  const setAspect = (type: EnumAllViewType, { width, height }: aspectType) => {
    mprAspects.value[type] = {
      width,
      height
    }
    if (mprAspects.value[EnumAllViewType.ax] && mprAspects.value[EnumAllViewType.cor] && mprAspects.value[EnumAllViewType.sag]) {
        onMprSizeGotCb(mprAspects.value)
    }
  }


  return {
    mprAspects,
    setAspect
  }
}
